package com.yd;

import com.doman.Student;
import com.resultmsg.BaseEnums;
import com.resultmsg.Result;
import com.resultmsg.Results;
import com.server.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RequestMapping(value = "/educloud")
@RestController
public class AuthenticationController {


    @Autowired
    private StudentMapper studentMapper;


    /**
     * 学生鉴权
     * @param bindcode
     * @return
     */
    @RequestMapping(value = "/auth-student",method = RequestMethod.GET)
    public Result authStudent(@RequestParam String bindcode) {
        try {

            Student student = studentMapper.selectByPrimaryByBindcode(bindcode);
            if(student.getPayStatus()>0){
                return Results.success("200", BaseEnums.SUCCESS.desc(),true);
            }else{
                return Results.success("200", BaseEnums.FAILURE.desc(),false);
            }

        }catch (Exception e){
                return  Results.failure( "500" , BaseEnums.FAILURE.desc(),null);
        }



//        if (student1.getActive() == 1 && student1.getPayStatus() == 1){
//            if (Dates.isEffectiveDate(new Date(),student1.getDueTime())){//大于当前时间为true
//                return Results.successWithData(true, "20000", "鉴权通过");
//            }else{//小于当前时间为false
//                student1.setPayStatus(0);
//                int updateByPrimaryKeySelective = studentMapper.updateByPrimaryKeySelective(student1);
//                return Results.successWithData(false, "20000", "鉴权失败");
//            }
//        }else{
//            return Results.successWithData(false, "20000", "鉴权失败");
//        }
    }
}
